package com.itheima.demo09DRUID连接池使用;

import com.alibaba.druid.pool.DruidDataSourceFactory;
import com.itheima.utils.JDBCUtils;

import javax.sql.DataSource;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.Properties;

/**
druid的使用步骤
	1.导入druid-1.0.0.jar的jar包
	2.复制druid.properties文件到src下，并设置对应参数
	3.加载properties文件的内容到Properties对象中
	4.创建Druid连接池，使用配置文件中的参数
	5.从Druid连接池中取出连接
	6.执行SQL语句
	7.关闭资源
 * @author Asin
 */
public class Demo09 {
	public static void main(String[] args) throws Exception {

//		Properties prop = new Properties();
//		prop.load(new FileInputStream("day03_JDBC\\src\\druid.properties"));
//		DataSource dataSource = DruidDataSourceFactory.createDataSource(prop);
		DataSource dataSource = JDBCUtils.getDataSource();
		Connection conn = dataSource.getConnection();


		String sql = "INSERT INTO user VALUES (?, ?, ?);";
		PreparedStatement pr = conn.prepareStatement(sql);
		pr.setString(1,"wangwu");
		pr.setString(2,"666");
		pr.setInt(3,2000);

		int i = pr.executeUpdate();
		System.out.println(i);
		conn.close();
		pr.close();
	}
}
